//
//  UserOrderDetailController.m
//  SmallElephant
//
//  Created by Faith on 2022/12/24.
//

#import "UserOrderDetailController.h"

@interface UserOrderDetailController () <UICollectionViewDelegate, UICollectionViewDataSource>

/// 导航菜单视图
@property (nonatomic, strong) UIView *navigationTitleView;

/// 状态信息
@property (nonatomic, strong) UILabel *statusInfo;

/// 列表视图
@property (nonatomic, strong) UICollectionView *listView;

/// 订单数据
@property (nonatomic, strong) NSDictionary *orderData;

/// 底部操作按钮
@property (nonatomic, strong) UIView *bottomView;

@end

@implementation UserOrderDetailController

- (void)viewDidLoad {
    // 顶部背景占位
    UIView *placeHolderView = [[UIView alloc] init];
    [self.view addSubview:placeHolderView style:@"position: absolute; width: 100%; height: 143px; background: url(bg-my-order@3x);"];
    [super viewDidLoad];
    
    // 设置自定义导航栏标题
    [self setCustomTitleView:self.navigationTitleView style:@"display: flex; flex-direction: row; align-self: center;"];
    // 添加状态信息
    [self.view addSubview:self.statusInfo style:@"display: flex; flex-direction: row; align-self: center; padding:5px; font-size: 14px; color: #666666;"];
    // 添加列表组件
    [self.view addSubview:self.listView style:@"display: flex; flex-grow: 1; align-items: center; margin-top: 10px;"];
    // 添加底部操作视图
    [self.view addSubview:self.bottomView style:@"display: flex; flex-direction: row; background: #FFFFFF; padding: 10px; padding-bottom: --safe-area-bottom;"];
    // 加载数据
    [self loadData];
    
}

/// 懒加载导航标题视图
- (UIView *)navigationTitleView {
    if(!_navigationTitleView) {
        _navigationTitleView = [[UIView alloc] init];
        // 图标
        UIImageView *customIconView = [UIImageView withImage:@"icon-order-pay-delay@3x"];
        [_navigationTitleView addSubview:customIconView style:@"display: flex; width: 20px; height: 20px; align-self: center;"];
        // 标题文字
        UILabel *customTitleTextView = [[UILabel alloc] init];
        customTitleTextView.text = @"等待付款";
        [_navigationTitleView addSubview:customTitleTextView style:@"display: flex; margin-left: 10px; font-size:16px; font-weight: bold;"];
    }
    return _navigationTitleView;
}


/// 懒加载状态信息组件
- (UILabel *)statusInfo {
    if(!_statusInfo) {
        // 搜索组件
        _statusInfo = [[UILabel alloc] init];
    }
    return _statusInfo;
}

- (UIView *)bottomView {
    if(!_bottomView) {
        _bottomView = [[UIView alloc] init];
        
        UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnCancel setTitle:@"取消订单" forState:UIControlStateNormal];
        [_bottomView addSubview:btnCancel style:@"display: flex; height: 40px; padding-left:20px; padding-right: 20px; border-radius: 5px; font-size: 14px; color: #333333; margin-right:10px;  border-width: 1px; border-color: #CECECE; background: #FFFFFF;"];
        
        UIButton *btnModify = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnModify setTitle:@"立即支付 ¥98.00" forState:UIControlStateNormal];
        [_bottomView addSubview:btnModify style:@"display: flex; flex: 1; height: 40px; border-radius: 5px; font-size: 14px; color: #FFFFFF; background: #EF2020;"];
    }
    return _bottomView;
}

/// 懒加载列表组件
- (UICollectionView *)listView {
    if(!_listView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumInteritemSpacing = 0; // 每列之间的最小间距
        layout.minimumLineSpacing = SIZE(10); // 每行之间的最小间距
        layout.sectionInset = UIEdgeInsetsMake(0, SIZE(10), SIZE(10), SIZE(10)); // 上下左右间距
        layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize;
        _listView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _listView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _listView.backgroundColor = [UIColor clearColor];
        _listView.delegate = self;
        _listView.dataSource = self;
        [_listView registerClass:[UserOrderDetailAddressCell class] forCellWithReuseIdentifier:@"kUserOrderDetailAddressCell"];
        [_listView registerClass:[UserOrderDetailProductInfoCell class] forCellWithReuseIdentifier:@"kUserOrderDetailProductInfoCell"];
        [_listView registerClass:[UserOrderDetailPriceCell class] forCellWithReuseIdentifier:@"kUserOrderDetailPriceCell"];
        [_listView registerClass:[UserOrderDetailInfoCell class] forCellWithReuseIdentifier:@"kUserOrderDetailInfoCell"];
    }
    return _listView;
}

/// 单元格数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

/// 列表单元视图
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.item==0) {
        UserOrderDetailAddressCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kUserOrderDetailAddressCell" forIndexPath:indexPath];
        [cell setData:self.orderData[@"addressInfo"]];
        return cell;
    } else if(indexPath.item==1) {
        UserOrderDetailProductInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kUserOrderDetailProductInfoCell" forIndexPath:indexPath];
        [cell setData:self.orderData[@"productInfo"]];
        return cell;
    } else if(indexPath.item==2) {
        UserOrderDetailPriceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kUserOrderDetailPriceCell" forIndexPath:indexPath];
        [cell setData:self.orderData[@"priceInfo"]];
        return cell;
    } else {
        UserOrderDetailInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kUserOrderDetailInfoCell" forIndexPath:indexPath];
        [cell setData:self.orderData[@"orderInfo"]];
        return cell;
    }
}

- (void)loadData {
    NSString *remainTimeString = @"05:13:53";
    NSMutableAttributedString *statusInfoAttrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"还剩 %@ 订单自动取消", remainTimeString]];
    [statusInfoAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#EF2020"] range:NSMakeRange(3, remainTimeString.length)];
    self.statusInfo.attributedText = statusInfoAttrString;
    
    self.orderData = @{
        @"addressInfo": @{
            @"name": @"王先生",
            @"phone": @"137****8975",
            @"address": @"云南省昆明市官渡区矣六街道商博街蓝湾俊园2005"
        },
        @"productInfo": @{
            @"title": @"睡不着了啊啊啊啊[苦涩][苦涩][苦涩]吃完外卖喝了两个小啤啤，一点困意都没了[跪了][跪了][跪了] ​",
            @"amount": @(18.23),
            @"number": @(3),
            @"spec": @[@"米白色长袖", @"均码"],
            @"cover": @"https://wx1.sinaimg.cn/orj360/002R448Kgy1huwcjn0pllj62c0340u0y02.jpg"
        },
        @"priceInfo": @{
            @"productAmount": @(150.24),
            @"shipFee": @(18.23),
            @"serviceFee": @(3.24),
            @"couponAmount": @(5.02),
            @"discount": @(30.24),
            @"needPay": @(120.00)
        },
        @"orderInfo": @{
            @"orderNum": @"304461277576",
            @"delivery": @"送货上门",
            @"orderTime": @"2024-10-28 10:25:33",
            @"remark": @"可以使用编程语言（例如 Swift、Python 等）对这类数据按 position 字段进行分组。以下是几种不同语言的实现示例："
        }
    };
    
    [self.listView reloadData];
}


@end



/// 订单地址单元格
@interface UserOrderDetailAddressCell()

/// 联系人名称和电话
@property (nonatomic, strong) UILabel *contactInfo;

/// 地址信息
@property (nonatomic, strong) UILabel *addressInfo;

@end

@implementation UserOrderDetailAddressCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    
    [self.contentView applyStyle:@"padding: 15px;"];
    
    // 联系信息
    _contactInfo = [[UILabel alloc] init];
    [self.contentView addSubview:_contactInfo style:@"font-size: 16px; color: #0D0D0D; font-size:14px; font-weight: bold;"];
    
    // 收货地址
    _addressInfo = [[UILabel alloc] init];
    _addressInfo.numberOfLines = 0;
    [self.contentView addSubview:_addressInfo style:@"margin-top: 6px; font-size: 14px; color: #666666;"];
    
}

- (CGSize)sizeThatFits:(CGSize)size {
    [self.contentView configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = true;
        layout.flexDirection = YGFlexDirectionColumn;
        layout.width = YGPointValue(SCREEN_WIDTH - SIZE(21));
    }];
    [self.contentView.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleHeight];
    return [self.contentView sizeThatFits:size];
}

- (void)setData:(NSDictionary *)data {
    self.contactInfo.text = [NSString stringWithFormat:@"%@ %@", data[@"name"], data[@"phone"]];
    self.addressInfo.text = [NSString stringWithFormat:@"%@", data[@"address"]];
}

@end




/// 商品信息单元格
@interface UserOrderDetailProductInfoCell()

/// 商品图片
@property (nonatomic, strong) UIImageView *coverView;

/// 商品名称
@property (nonatomic, strong) UILabel *productName;

/// 规格信息
@property (nonatomic, strong) UILabel *specInfo;

/// 订单金额
@property (nonatomic, strong) UILabel *orderAmount;

/// 商品数量
@property (nonatomic, strong) UILabel *productNumber;

@end

@implementation UserOrderDetailProductInfoCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    
    [self.contentView applyStyle:@"padding: 15px;"];
    
    // 订单信息
    UIView *orderInfo = [[UIView alloc] init];
    [self.contentView addSubview:orderInfo style:@"display: flex; flex-direction: row;"];
    // 商品封面
    _coverView = [[UIImageView alloc] init];
    [orderInfo addSubview:_coverView style:@"display: flex; width: 80px; height: 80px; border-radius: 5px;"];
    
    // 商品标题和规格
    UIView *infoView = [[UIView alloc] init];
    [orderInfo addSubview:infoView style:@"display: flex; flex: 1; flex-direction: column; margin-left: 8px; "];
    // 商品标题
    _productName = [[UILabel alloc] init];
    _productName.numberOfLines = 2;
    [infoView addSubview:_productName style:@"font-size: 14px; color: #0D0D0D; margin-top: 5px;"];
    // 商品规格
    _specInfo = [[UILabel alloc] init];
    [infoView addSubview:_specInfo style:@"margin-top: 10px; font-size: 12px; color: #666666;"];
    
    // 订单金额和数量
    UIView *orderAmountAndNumber = [[UIView alloc] init];
    [orderInfo addSubview:orderAmountAndNumber style:@"display: flex; flex-direction: column; margin-top: 5px; margin-left: 10px; align-items: flex-end;"];
    
    // 订单金额
    _orderAmount = [[UILabel alloc] init];
    _orderAmount.font = [UIFont systemFontOfSize:FONT_SIZE(12) weight:UIFontWeightBold];
    [orderAmountAndNumber addSubview:_orderAmount style:@"display: flex; color: #333333;"];
    // 商品数量
    _productNumber = [[UILabel alloc] init];
    [orderAmountAndNumber addSubview:_productNumber style:@"display: flex; width: 100%; text-align: right; margin-top: 5px; font-size: 13px; color: #666666;"];
    
    // 分割线
    UIView *lineView = [[UIView alloc] init];
    [self.contentView addSubview:lineView style:@"display: flex; border-width: 1px; height: 1px; border-color: #F1F1F1; margin-top: 15px; margin-bottom: 15px;"];
    
    // 按钮操作组
    UIView *operationButton = [[UIView alloc] init];
    [self.contentView addSubview:operationButton style:@"display: flex; flex-direction: row; justify-content: center; align-items: center;"];
    
    UIImageView *contactIconView = [[UIImageView alloc] initWithImage:[UIImage imageWithName:@"icon-live-suppert@3x"]];
    [operationButton addSubview:contactIconView style:@"display: flex; width: 18px; height: 18px;"];
    
    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnCancel setTitle:@"联系客服" forState:UIControlStateNormal];
    [operationButton addSubview:btnCancel style:@"display: flex; height: 30px; padding-left:10px; font-size: 14px; color: #333333;"];
    
}

- (CGSize)sizeThatFits:(CGSize)size {
    [self.contentView configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = true;
        layout.flexDirection = YGFlexDirectionColumn;
        layout.width = YGPointValue(SCREEN_WIDTH - SIZE(21));
    }];
    [self.contentView.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleHeight];
    return [self.contentView sizeThatFits:size];
}

- (void)setData:(NSDictionary *)data {
    [self.coverView setImageUrl:data[@"cover"]];
    self.productName.text = [NSString stringWithFormat:@"%@", data[@"title"]];
    self.specInfo.text = [data[@"spec"] componentsJoinedByString:@", "];
    // 格式化价格
    NSString *orderAmountString = [NSString stringWithFormat:@"%.2f", [data[@"amount"] floatValue]];
    NSRange dotRange = [orderAmountString rangeOfString:@"."];
    NSMutableAttributedString *orderAmountAttributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", orderAmountString]];
    [orderAmountAttributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:FONT_SIZE(18)] range:NSMakeRange(1, dotRange.location)];
    self.orderAmount.attributedText = orderAmountAttributeString;
    // 设置数量
    self.productNumber.text = [NSString stringWithFormat:@"共%@件", data[@"number"]];
}

@end




/// 订单价格单元格
@interface UserOrderDetailPriceCell()

/// 标题
@property (nonatomic, strong) UILabel *title;

/// 对应值
@property (nonatomic, strong) UILabel *value;

@end

@implementation UserOrderDetailPriceCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    [self.contentView applyStyle:@"padding: 15px;"];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"价格明细";
    [self.contentView addSubview:titleLabel style:@"font-size: 16px; font-weight: bold; color: #333333; margin-bottom: 10px;"];
}

- (CGSize)sizeThatFits:(CGSize)size {
    [self.contentView configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = true;
        layout.flexDirection = YGFlexDirectionColumn;
        layout.width = YGPointValue(SCREEN_WIDTH - SIZE(21));
    }];
    [self.contentView.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleHeight];
    return [self.contentView sizeThatFits:size];
}

- (void)setData:(NSDictionary *)data {
    if(data[@"productAmount"]) {
        //
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 5px; "];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"商品价格";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"￥%@", data[@"productAmount"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
        
        // 箭头
        UIImageView *arrowView = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"chevron.right"]];
        arrowView.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
        [itemView addSubview:arrowView style:@"display: flex; flex: 0; width: 8px; height: 12px; margin-left: 5px; align-self: center;"];
        
    }
    if(data[@"shipFee"]) {
        
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"运费";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"￥%@", data[@"shipFee"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
        // 箭头
        UIImageView *arrowView = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"chevron.right"]];
        arrowView.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
        [itemView addSubview:arrowView style:@"display: flex; flex: 0; width: 8px; height: 12px; margin-left: 5px; align-self: center;"];
    }
    if(data[@"serviceFee"]) {
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"服务费";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"￥%@", data[@"serviceFee"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
        // 箭头
        UIImageView *arrowView = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"chevron.right"]];
        arrowView.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
        [itemView addSubview:arrowView style:@"display: flex; flex: 0; width: 8px; height: 12px; margin-left: 5px; align-self: center;"];
    }
    if(data[@"couponAmount"]) {
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"优惠券";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"-￥%@", data[@"couponAmount"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #EF2020; text-align: right; margin-left: 10px;"];
        // 箭头
        UIImageView *arrowView = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"chevron.right"]];
        arrowView.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
        [itemView addSubview:arrowView style:@"display: flex; flex: 0; width: 8px; height: 12px; margin-left: 5px; align-self: center;"];
    }
    // 分割线
    UIView *lineView = [[UIView alloc] init];
    [self.contentView addSubview:lineView style:@"display: flex; border-width: 1px; height: 1px; border-color: #F1F1F1; margin-top: 15px; margin-bottom: 15px;"];
    // 价格汇总
    UILabel *value = [[UILabel alloc] init];
    value.text = [NSString stringWithFormat:@"共减 ￥%.2f  需付款 ￥%.2f", [data[@"discount"] floatValue], [data[@"needPay"] floatValue]];
    [self.contentView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #EF2020; text-align: right; margin-left: 10px;"];
    
}

@end




/// 订单信息单元格
@interface UserOrderDetailInfoCell()

/// 商品名称
@property (nonatomic, strong) UILabel *contactInfo;

/// 规格信息
@property (nonatomic, strong) UILabel *addressInfo;

@end

@implementation UserOrderDetailInfoCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    
    [self.contentView applyStyle:@"padding: 15px;"];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"订单信息";
    [self.contentView addSubview:titleLabel style:@"font-size: 16px; font-weight: bold; color: #333333; margin-bottom: 10px;"];
    
}

- (CGSize)sizeThatFits:(CGSize)size {
    [self.contentView configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = true;
        layout.flexDirection = YGFlexDirectionColumn;
        layout.width = YGPointValue(SCREEN_WIDTH - SIZE(21));
    }];
    [self.contentView.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleHeight];
    return [self.contentView sizeThatFits:size];
}

- (void)setData:(NSDictionary *)data {
    if(data[@"orderNum"]) {
        //
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 5px; "];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"订单编号";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"%@", data[@"orderNum"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
        
        // 复制按钮
        UIButton *btnCopy = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnCopy setImage:[UIImage imageWithName:@"icon-copy@3x"] forState:UIControlStateNormal];
        [itemView addSubview:btnCopy style:@"display: flex; flex: 0; width: 20px; height: 20px; margin-left: 5px; align-self: center;"];
        
    }
    if(data[@"delivery"]) {
        
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"配送服务";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"%@", data[@"delivery"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
    }
    if(data[@"orderTime"]) {
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"下单时间";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333; "];
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.text = [NSString stringWithFormat:@"%@", data[@"orderTime"]];
        [itemView addSubview:value style:@"display: flex; flex: 1; font-size: 14px; color: #333333; text-align: right; margin-left: 10px;"];
    }
    if(data[@"remark"]) {
        UIView *itemView = [[UIView alloc] init];
        [self.contentView addSubview:itemView style:@"display: flex; flex-direction: row; margin-top: 10px; justify-content: space-between; align-items: flex-start;"];
        // 标题
        UILabel *title = [[UILabel alloc] init];
        title.text = @"订单备注";
        [itemView addSubview:title style:@"display: flex; flex: 0; font-size: 14px; color: #333333;"];
        
        
        UIView *valueView = [[UIView alloc]init];
        [itemView addSubview:valueView style:@"display: flex; flex: 1; justify-content: space-between; margin-left: 10px;"];
        
        // 标题值
        UILabel *value = [[UILabel alloc] init];
        value.lineBreakMode = NSLineBreakByTruncatingTail;
        value.numberOfLines = 0;
        value.text = [NSString stringWithFormat:@"%@", data[@"remark"]];
        [valueView addSubview:value style:@"display: flex; font-size: 14px; color: #333333; align-self: flex-end;"];
    }
}


@end
